package com.holyn.guofang.viewcommon.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.holyn.guofang.R;
import com.holyn.guofang.viewcommon.radiobutton.DrawableCenterRadioButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Holyn on 2017/6/8.
 */

public class PayWayDialog extends Dialog {
    @BindView(R.id.rb_pay_way_1)
    DrawableCenterRadioButton rbPayWay1;
    @BindView(R.id.rb_pay_way_2)
    DrawableCenterRadioButton rbPayWay2;
    @BindView(R.id.rg_pay_way)
    RadioGroup rgPayWay;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;

    Integer payWay = 1;//支付方式(1:线下支付，2:银联支付，3:支付宝 支付，4:苹果支付)

    private Context context;

    private OnSureClickListener onSureClickListener = null;
    private OnClickListener onStatusClickListener = null;

    public interface OnSureClickListener {
        void onSureClick(Integer payWay);
    }

    public PayWayDialog(@NonNull Context context) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        this.context = context;
        initView();
    }

    public PayWayDialog(@NonNull Context context, OnSureClickListener onSureClickListener) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        this.context = context;
        initView();
        this.onSureClickListener = onSureClickListener;
    }

    public PayWayDialog(@NonNull Context context, OnClickListener onStatusClickListener, OnSureClickListener onSureClickListener) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        this.context = context;
        initView();
        this.onStatusClickListener = onStatusClickListener;
        this.onSureClickListener = onSureClickListener;
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_pay_way, null);
        setContentView(dialogView);
        ButterKnife.bind(this);
        setCanceledOnTouchOutside(false);

        rgPayWay.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId){
                    case R.id.rb_pay_way_1:
                        payWay = 3;
                        break;
                    case R.id.rb_pay_way_2:
                        payWay = 1;
                        break;
                }
            }
        });
    }

    public OnSureClickListener getOnSureClickListener() {
        return onSureClickListener;
    }

    public void setOnSureClickListener(OnSureClickListener onSureClickListener) {
        this.onSureClickListener = onSureClickListener;
    }

    @OnClick({R.id.tv_sure, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sure:
                if (onSureClickListener != null){
                    onSureClickListener.onSureClick(payWay);
                }
                PayWayDialog.this.dismiss();
                break;
            case R.id.tv_cancel:
                PayWayDialog.this.dismiss();
                break;
        }
    }
}
